package com.panshi.modules.controller;


import com.panshi.modules.service.ThAboutService;
import com.panshi.vo.R;
import com.panshi.vo.ThAbout;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器 :栏目关于
 * </p>
 *
 * @author 857
 * @since 2020-07-29
 */
@Api(tags = "关于栏目")
@RestController
@CrossOrigin
@RequestMapping("/api/th/about")
public class ThAboutController {

    @Autowired
    private ThAboutService thAboutService;

    @GetMapping("list")
    @ApiOperation("获取栏目集合接口")
    public List<ThAbout> listThAbout() {
        return thAboutService.listThAbout();
    }

    @GetMapping("/{id}")
    @ApiOperation("ID获取信息接口")
    public ThAbout getThAbout(@PathVariable("id") Integer id) {
        return thAboutService.getThAbout(id);
    }

    @PostMapping
    @ApiOperation("新增栏目接口")
    public R addThAbout(@RequestBody ThAbout thAbout) {
        int result = thAboutService.addThAbout(thAbout);
        if(result > 0){
            return R.ok();
        }
        return R.error();
    }

    @PutMapping
    @ApiOperation("编辑栏目接口")
    public R editThAbout(@RequestBody ThAbout thAbout) {
        int result = thAboutService.editThAbout(thAbout);
        if(result > 0){
            return R.ok();
        }
        return R.error();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除栏目接口")
    public R delThAbout(@PathVariable("id") Integer id) {
        int result = thAboutService.delThAbout(id);
        if(result > 0){
            return R.ok();
        }
        return R.error();
    }
}

